fix(dock): debounce tray plugin list logging to ensure stable state#1597
fix(dock): debounce tray plugin list logging to ensure stable state#1597Ivy233 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces the fixed 3‑second delayed logging of tray plugin lists with a debounced logging mechanism triggered by plugin change events, and adjusts dde-application-manager packaging dependencies. Sequence diagram for debounced tray plugin list loggingsequenceDiagram
participant TrayApplet
participant DockDBusProxy
participant DebounceTimer
TrayApplet->>DockDBusProxy: pluginsChanged()
DockDBusProxy->>DockDBusProxy: scheduleDebouncedLog()
alt first_call_or_timer_not_created
DockDBusProxy->>DebounceTimer: create QTimer
DockDBusProxy->>DebounceTimer: setSingleShot(true)
DockDBusProxy->>DebounceTimer: setInterval(2000)
DebounceTimer-->>DockDBusProxy: timeout (connected to logInitialPluginState)
end
DockDBusProxy->>DebounceTimer: start()
rect rgb(230,230,230)
Note over DebounceTimer: 2s debounce window
end
DebounceTimer-->>DockDBusProxy: timeout
DockDBusProxy->>DockDBusProxy: logInitialPluginState()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the hardcoded 2000 ms debounce interval into a named constant or configuration value so the debounce behavior is easier to adjust and understand in the future.
- The QTimer timeout connection in
scheduleDebouncedLoguses a lambda that simply callslogInitialPluginState; replacing this with a direct slot connection would simplify the code and avoid an extra indirection.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the hardcoded 2000 ms debounce interval into a named constant or configuration value so the debounce behavior is easier to adjust and understand in the future.
- The QTimer timeout connection in `scheduleDebouncedLog` uses a lambda that simply calls `logInitialPluginState`; replacing this with a direct slot connection would simplify the code and avoid an extra indirection.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
248ac3d to
f8b4b72
Compare
Replace fixed 3-second delay with debounce mechanism for tray plugin list event logging. The original approach reported plugin state immediately upon tray applet connection and again after a fixed 3-second delay, which could capture incomplete plugin lists during login. Use a 2-second debounce timer that resets on each pluginsChanged signal, ensuring the log only records the final stable plugin list. Also adjust dde-application- manager packaging dependencies. 将托盘插件列表事件上报从固定3秒延迟改为防抖机制。 原始方案在托盘小程序连接后立即上报并延迟3秒再报一次, 在登录时可能捕获到不完整的插件列表。 改用2秒防抖定时器,每次插件列表变化时重置, 确保只记录最终稳定的插件列表。同时调整 dde-application-manager 打包依赖。 PMS: BUG-361067
f8b4b72 to
2e5d44d
Compare
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff,本次修改主要涉及 Debian 打包依赖版本调整,以及 Dock 插件状态日志记录的防抖逻辑重构。 总体来说,这次修改将原本的固定延时日志记录改为了基于事件驱动的防抖逻辑,这是一个很好的优化,可以避免在插件频繁变动时产生冗余日志。但在依赖版本管理、Qt 内存与对象生命周期管理以及代码健壮性方面,我有一些改进建议。 以下是详细的审查意见: 1. 语法与逻辑1.1 依赖版本运算符不一致(Debian Control)
1.2 首次加载的立即触发逻辑存在隐患
2. 代码质量2.1 对象生命周期与内存管理
2.2 代码封装与复用
3. 代码性能3.1 信号连接的冗余
4. 代码安全4.1 日志注入与敏感信息泄露
💡 综合改进后的代码建议基于以上分析,我为你重构了 C++ 部分的代码,使其更符合 Qt 的最佳实践,逻辑更清晰:
// Debounce timer to ensure the plugin list has stabilized before logging
-QTimer *m_debounceTimer = nullptr;
+QTimer m_debounceTimer; // 直接使用对象,避免堆分配和指针管理
DockDBusProxy::DockDBusProxy(DockPanel* parent)
: QObject(parent)
, m_debounceTimer()
{
// 设置单次触发和防抖间隔
m_debounceTimer.setSingleShot(true);
m_debounceTimer.setInterval(2000);
// 直接连接到目标函数,无需Lambda包装
connect(&m_debounceTimer, &QTimer::timeout, this, &DockDBusProxy::logInitialPluginState);
// ... 原有其他初始化代码 ...
}
connect(m_trayApplet, SIGNAL(pluginsChanged()), this, SIGNAL(pluginsChanged()));
- // Trigger a debounced log on each change, and also schedule one immediately after first load
- connect(this, &DockDBusProxy::pluginsChanged, this, &DockDBusProxy::scheduleDebouncedLog);
- scheduleDebouncedLog();
+ // 当插件列表发生变化时,重置防抖定时器
+ connect(this, &DockDBusProxy::pluginsChanged, this, [this]() {
+ m_debounceTimer.start();
+ });
+ // 首次加载完成后,启动防抖定时器(2秒后若无变动则记录日志)
+ m_debounceTimer.start();
}
});
Debian Control 修改建议: - dde-application-manager-api (>= 1.2.48),
+ dde-application-manager-api (>= 1.2.51), # 与运行时依赖保持一致
dde-api-dev (>> 6.0.39),
dde-tray-loader-dev (> 2.0.24),
extra-cmake-modules,
---
- dde-application-manager (>> 1.2.51),
+ dde-application-manager (>= 1.2.51), # 统一使用 >= 运算符
${misc:Depends}, |
Replace fixed 3-second delay with debounce mechanism for tray plugin list event logging. The original approach reported plugin state immediately upon tray applet connection and again after a fixed 3-second delay, which could capture incomplete plugin lists during login.
Use a 2-second debounce timer that resets on each
pluginsChanged signal, ensuring the log only records the final stable plugin list. Also adjust dde-application- manager packaging dependencies.
将托盘插件列表事件上报从固定3秒延迟改为防抖机制。
原始方案在托盘小程序连接后立即上报并延迟3秒再报一次,
在登录时可能捕获到不完整的插件列表。
改用2秒防抖定时器,每次插件列表变化时重置,
确保只记录最终稳定的插件列表。同时调整
dde-application-manager 打包依赖。
PMS: BUG-361067
PS: 打包依赖是dde-am修改的时候,依赖调整,如果需要单独提pr就comment一下。调整pr原因:
版本号来源:linuxdeepin/dde-application-manager#354
依赖修改对应pr:#1590
Summary by Sourcery
Debounce logging of the dock tray plugin list so it records only the final stable state after plugin changes.
Bug Fixes:
Enhancements:
Build: